home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh -f
- # bash in fact. Linux' bash. I don't have bourne shell! :( Should be ok tho.
- # My bourne shell scripting skills are pretty reduced. Lot to improve there.
- # I prefer using the separate commands but some people don't like it.
- # This is FSP Sh , the Shell Script FSP command interpreter by MegaFork, 1.01
- # WHAT TO DO ?!?!
- # ---------------
- # For quick start, just put the absolute path of your fsp271mf binaries in
- # FSP_PATH=/usr/local/bin
- # then run fspsh, try a few things. Improve my script. mail me your version ;)
- #
- # fsp-client and FSPSh : some pros and some cons ...
- # It's of course ridiculously rudimentary compared to the fsp-client.
- # It obviously doesn't like VMS. So do I. No support for VMS ;)
- # I have some problems with parsing. Especially with the -f flag.Can't change.
- # But it works with my hacked FSP ;) and it should be smaller than having both
- # the separate commands and the fspclient. Another good thing is you can
- # compress it (alias fsp sh \`compress\<fspsh.Z\`) without having to wait too
- # much on start. Its portability should be better than fsp-client's, since a
- # side effect of my little scripting-knowledge is that I use a very reduced set
- # of commands ;) .
- # It's alot more hackable. If it ever becomes popular, it should be improved
- # much more faster ...
- # It's `ready-for-use'. No Makefile tweaking.
- #
- # Please tell me what you have improved in it, I'm sure you did.
- # FspSh's specific commands.
- # motd: the root dir's .README.
- # echo <string>: just performs an 'echo' ( Useful for macros ... )
- # prompt: change the prompt... Warning: I parse prompts: special shell chars
- # should be quoted twice... but this allow envs to be parsed.
- # example: prompt $FSP_HOST:$FSP_PORT:$FSP_DIR\\> ( yeah, tricky )
- # bat: start logging action in a shell script.
- # enbat: end logging actions.
- # batfile <file>: set shell script filename.
- # run <file>: run a *batch* file.
- # (note: if you want a rc, just make a bat, and put the filename at FSPSH_RC=)
- # macro: start a macro.
- # endmacro: end recording.
- # log <file>: set logfile.( where the macros will be appent. Remove if you
- # wish to make a new file )
- #
- # coreleft: prints out the space left in kbytes (only on FSP servers that run
- # hacked version and have that option enabled)
- #
- # How to Run a Previously recored macro?
- # just fspsh < <logfilename> or fspsh <logfilename>
- # the second form is highly recommended over the first one.
- # Note that incomplete name will cause fspsh to look in the current dir for
- # the filename, and if not found in $FSP_PATH/filename. Macros that don't end
- # with a `quit' are corrected.
- # WARNING: macro doesn't destroy your old file. It appends to it.
- # WARNING: bat doesn't append to file. It starts a new one.
- # this `quick help' is taking too much. I'll make a separate info file I guess.
-
- #function args { echo $ |cut -d' ' -f2- }
-
- # Default Host.
- FSP_PORT=6999
- FSP_HOST=localhost
- FSP_DELAY=3000
- FSP_TRACE=
- FSP_DIR=/
-
- # Where your FSP clients reside. Absolute path.
- FSP_PATH=/usr/local/bin
- FSPSH_PROMPT='fsp\> '
- #FSPSH_PROMPT="\$FSP_HOST:\$FSP_PORT:\$FSP_DIR\>"
- RECORD_FILE=$FSP_PATH/macros
- BATCH_FILE=/batch
- BATCH_PATH=`pwd`
- FSPSH_RC=
-
- # You shouldn't have to edit below this line unless you're improving the script.
-
- BATCHING=OFF
- IS_RECORDING=NO
- export FSP_PATH
- source $FSPSH_RC
- if [ $1x != x ]
- then
- echo Running Macro $1.
- MACRONAME=$1
- if [ `basename $1` = $1 ] ; then
- if [ ! -f $1 ] ; then
- echo Correcting $1 to $FSP_PATH/$1
- MACRONAME=$FSP_PATH/$1
- fi
- fi
- if [ "`tail -1 $MACRONAME`" != quit ] ;then
- echo quit >> $MACRONAME # if it was `exit' then oh well it'll have two.
- fi
- fspsh < $MACRONAME
- exit 0
- fi
-
- export FSP_HOST
- export FSP_PORT
- export FSP_DELAY
- export FSP_TRACE
- export FSP_DIR
- export FSP_PASSWORD
- export IS_RECORDING
- export RECORD_FILE
-
- while [ 1 ]
- do
- #echo -n 'fsp> '
- echo -n "`eval echo $FSPSH_PROMPT` "
- read line
- if [ $IS_RECORDING = YES ]
- then
- echo "$line" >>$RECORD_FILE
- fi
- cmd=`echo $line|cut -d' ' -f1`
- export SHCMD=
- case $cmd in
- quit|exit) echo Goodbye.;SHCMD="exit 0";;
- ver*) echo Shell Script FSP Interpreter 1.01 by Patrick Nguyen - MegaFork
- #$FSP_PATH/fver x # local ver displayed when fver is given an arg.
- #$FSP_PATH/fver # server ver displayed when fver is given no args.
- SHCMD='$FSP_PATH/fver x;$FSP_PATH/fver'
- SHCMD="eval $SHCMD"
- ;;
- help) if [ `echo $line|wc -w` != 2 ] ;then
- echo Shell Script FSP Interpreter by Patrick Nguyen - MegaFork
- echo Available commands \(Unsorted\):
- echo "motd open close port pass trace delay"
- echo "dir cd put get ldir lpwd lcd"
- echo "rmdir mkdir show du pwd grab pro"
- echo "find ls shell ver quit del macro"
- echo "endmacro logfile echo prompt ! bat batfile"
- echo "endbat run coreleft touch"
- echo typing help \<cmd\> should \(hopefully\) print out a quick help.
- else echo You have tried ${line}. I\'ll make quick online docs available
- echo as soon as I figure out how to do imbricated case ...But now
- echo I guess i\'ll go to sleep.
- fi;;
- echo) SHCMD="$line";;
- motd) SHCMD="$FSP_PATH/fprocmd /";;
- prompt) SHCMD="export FSPSH_PROMPT=`echo $line|cut -d' ' -f2-` ";;
- coreleft) # Only on server that use fsp.271mf with the quota option enabled.
- if [ `$FSP_PATH/flscmd -1 /|grep FSP_LEFT`x != x ] ;then
- # I'll make a better one when I'll have time
- SHCMD='eval echo There is \`echo `$FSP_PATH/fcatcmd /FSP_LEFT|head -1`/1000\|bc\` kb left'
- SHCMD="`eval echo $SHCMD`"
- else
- SHCMD="echo No quota here."
- fi
- ;;
- open|o)
- SHCMD="export FSP_HOST=`echo $line|cut -d' ' -f2`"
- FSP_HOST=`echo $line|cut -d' ' -f2`
- if [ `echo $line|wc -w` != 2 ] ;then
- SHCMD="$SHCMD\;FSP_PORT=`echo $line|cut -d' ' -f3`"
- FSP_PORT=`echo $line|cut -d' ' -f3`
- fi
- echo Setting Host: $FSP_HOST : $FSP_PORT
- ;;
- close)
- echo Don\'t need to \`close\', since there\'s no connection.;;
- port) SHCMD="export FSP_PORT=`echo $line|cut -d' ' -f2`"
- echo Setting Port: `echo $line|cut -d' ' -f2` \(Host is $FSP_HOST\)
- ;;
- pass) SHCMD="export FSP_PASSWORD=`echo $line|cut -d' ' -f2`";echo Ok.;;
- trace) SHCMD="export FSP_TRACE=`echo $line|cut -d' ' -f2`"
- echo TRACE value is now: `echo $line|cut -d' ' -f2`.;;
- delay) SHCMD="export FSP_DELAY=`echo $line|cut -d' ' -f2`"
- echo Delay: `echo $line|cut -d' ' -f2`;;
- dir) if [ `echo $line|wc -w` != 1 ]
- then
- ARGS=`echo $line|cut -d' ' -f2-`
- else ARGS=
- fi
- SHCMD="$FSP_PATH/flscmd -lA $ARGS";;
- cd) if [ `echo $line|wc -w` != 1 ] ;then
- ARGS=`echo $line|cut -d' ' -f2-` ; else ARGS=
- fi
- SHCMD="export FSP_DIR=`$FSP_PATH/fcdcmd $ARGS`";;
- #put|get)
- put) SHCMD="$FSP_PATH/fput `echo $line|cut -d' ' -f2-`" ;;
- get) SHCMD="$FSP_PATH/fgetcmd `echo $line|cut -d' ' -f2-`" ;;
- ldir) if [ `echo $line|wc -w` != 1 ] ;then
- ARGS=`echo $line|cut -d' ' -f2-`
- else ARGS=
- fi
- SHCMD="ls -lA $ARGS" ;;
- lcd) SHCMD="cd `echo $line|cut -d' ' -f2`" ;;
- lpwd) echo cwd is now: `pwd`;;
- #mkdir|rmdir) Goddam ppl who wrote fsp don't like to be coherent do they.
- rmdir) SHCMD="$FSP_PATH/f${cmd}cmd `echo $line|cut -d' ' -f2`"
- ;;
- mkdir) SHCMD="$FSP_PATH/f$line" ;;
- cat|show) SHCMD="$FSP_PATH/fcatcmd `echo $line|cut -d' ' -f2-`" ;;
- del|rm) SHCMD="$FSP_PATH/frmcmd `echo $line|cut -d' ' -f2-`" ;;
- du) if [ `echo $line|wc -w` != 1 ] ;then ARGS=`echo $line|cut -d' ' -f2-`
- else ARGS= ;fi
- SHCMD="$FSP_PATH/fducmd $ARGS" ;;
- pwd) echo $FSP_DIR on $FSP_HOST port $FSP_PORT ;;
- grab|pro|find|ls)
- if [ `echo $line|wc -w` != 1 ] ;then
- ARGS=`echo $line|cut -d' ' -f2-`
- else ARGS=
- fi
- SHCMD="$FSP_PATH/f${cmd}cmd $ARGS"
- ;;
- touch) FILE=`echo $line|cut -d' ' -f2`
- SHCMD='touch $FILE;$FSP_PATH/fput $FILE;rm -f $FILE'
- SHCMD="eval $SHCMD"
- ;;
- shell) /bin/sh -i;;
- log) RECORD_FILE=`echo $line|cut -d' ' -f2`
- echo Setting logfile value to $RECORD_FILE .
- ;;
- macro) echo Starting Record. \( $RECORD_FILE \)
- IS_RECORDING=YES ;;
- endmacro) echo Stopping Record. \( $RECORD_FILE \) ; IS_RECORDING=NO ;;
- bat) echo Starting BATCH record. \( $BATCH_PATH/$BATCH_FILE \).
- echo "#!/bin/sh" >$BATCH_PATH/$BATCH_FILE
- export BATCHING=ON ;;
- endbat) echo Ending BATCH recording. \( $BATCH_PATH/$BATCH_FILE \).
- export BATCHING=OFF ;;
- batfile) if [ `echo $line|wc -w` != 2 ] ;then
- echo Current BATH file\'s value is $BATCH_PATH/$BATCH_FILE .
- else
- BATCH_FILE=`echo $line|cut -d' ' -f2`
- if [ `basename $BATCH_FILE` != $BATCH_FILE ]
- then
- BATCH_PATH=`echo $BATCH_FILE | sed -e 's;/[a-zA-Z0-9]*$;;'`
- BATCH_FILE=`basename $BATCH_FILE`
- fi
- echo Setting BATCH file\'s value to $BATCH_PATH/$BATCH_FILE .
- fi
- ;;
- run|source) SHCMD="source `echo $line|cut -d' ' -f2-`" ;;
- \!) /bin/sh -c "`echo $line|cut -d' ' -f2-`" ;;
- *) if [ ${line}x != x ] ;then
- echo Unknown Command: $cmd
- fi;;
- esac
- if [ "${SHCMD}"x != x ] ;then
- if [ $BATCHING = ON ] ;then
- echo "$SHCMD">>$BATCH_PATH/$BATCH_FILE
- fi
- $SHCMD
- fi
- export FSP_HOST
- export FSP_PORT
- export FSP_DIR
- export FSP_TRACE
- export FSP_DELAY
- export FSP_PASSWORD
- done
-